package com.xtkj.superclub_shop.controller;

import com.xtkj.commons.JsonResult;
import com.xtkj.superclub_entity.entity.shop.*;
import com.xtkj.superclub_shop.service.IProService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lizheqi
 * @create 2019-12-25-14:57
 */
@RestController
@RequestMapping("/pro")
public class ProController {

    @Autowired
    private IProService proService;


    /**
     * 查询所有上架商品的信息
     * @return
     */
    @RequestMapping(value = "/ground",method = RequestMethod.GET)
    public JsonResult getGroundPros(){
        try{
            List<Product> pros = proService.getGroundPros();
            return JsonResult.success("OK").setData(pros).setCode(200);
        }catch (Exception e){
            e.printStackTrace();
            return JsonResult.error(e.getMessage()).setCode(400);
        }
    }

    /**
     * 查询所有一级分类的类型
     * @return
     */
    @RequestMapping(value = "/epcType",method = RequestMethod.GET)
    public JsonResult getEpcTypes(){
        try {
            List<ProType> epcTypes = proService.getEpcType();
            System.out.println(epcTypes);
            return JsonResult.success("OK").setData(epcTypes).setCode(200);
        }catch (Exception e){
            e.printStackTrace();
            return JsonResult.error(e.getMessage()).setCode(400);
        }
    }

    /**
     * 查询一级分类下面的所有二级分类的类型
     * @return
     */
    @RequestMapping(value = "/epcType/epcChildType/{epcId}",method = RequestMethod.GET)
    public JsonResult getEpcChildTypes(@PathVariable String epcId){
        try {
            List<ProType> epcChildTypes = proService.getEpcChildTypes(epcId);
            return JsonResult.success("OK").setData(epcChildTypes).setCode(200);
        }catch (Exception e){
            e.printStackTrace();
            return JsonResult.error(e.getMessage()).setCode(400);
        }
    }

    /**
     * 查询一级分类下面的所有商品
     * @return
     */
    @RequestMapping(value = "/epcType/{epcId}",method = RequestMethod.GET)
    public JsonResult getEpcPros(@PathVariable String epcId){
        try {
            List<Product> pros = proService.getEpcPros(epcId);
            return JsonResult.success("OK").setData(pros).setCode(200);
        }catch (Exception e){
            e.printStackTrace();
            return JsonResult.error(e.getMessage()).setCode(400);
        }
    }

    /**
     * 查询二级分类下面的所有商品
     * @return
     */
    @RequestMapping(value = "/ecpChildType/{epcChildId}",method = RequestMethod.GET)
    public JsonResult getEpcChildPros(@PathVariable String epcChildId){
        try {
            List<Product> pros = proService.getEpcChildPros(epcChildId);
            return JsonResult.success("OK").setData(pros).setCode(200);
        }catch (Exception e){
            e.printStackTrace();
            return JsonResult.error(e.getMessage()).setCode(400);
        }
    }

    /**
     * 查询商品的详细信息
     * @return
     */
    @RequestMapping(value = "/get/{proId}",method = RequestMethod.GET)
    public JsonResult getProByProId(@PathVariable("proId") String proId){
        try {
            List<ProColorSizeMap> proColorSizes = proService.getProByProId(proId);
            return JsonResult.success("OK").setData(proColorSizes).setCode(200);
        }catch (Exception e){
            e.printStackTrace();
            return JsonResult.error(e.getMessage()).setCode(400);
        }
    }



}
